package pers.qianyu.month_202101.date_20210123;

/**
 * 35. 搜索插入位置
 * https://leetcode-cn.com/problems/search-insert-position/
 *
 * @author mizzle rain
 * @date 2021-01-23 16:05
 */
public class SearchInsert {
    public int searchInsert(int[] nums, int target) {
        int len = nums.length;
        if (len == 0) return 0;
        int left = 0, right = len - 1;
        while (left < right) {
            int mid = (left + right + 1) >> 1;
            if (nums[mid] <= target) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        return nums[left] >= target ? left : left + 1;
    }
}
